var myItemPicker = myApp.directive('myItemPicker', ['$rootScope', '$timeout', '$parse', function ($rootScope, $timeout, $parse) {
    return {
        restrict: 'E',
        scope: {
            ngModel: '=',
            csBindValue: '=?csBindValue',
            ngDisabled: '=?ngDisabled',
            csParameters: '='
        },
        link: function ($scope, element, attrs) {
            var code = attrs.csCode;

            var parameters = $scope.csParameters;

            var multiple = attrs.multiple;
            if (multiple) {
                multiple = multiple.toLowerCase() == 'false' ? false : true
            } else {
                multiple = false;
            }
            var render = function () {
            };
            $scope.option = {
                modalTitle: '选择项目',
                modalUrl: 'System/DataSource/picker',
                multiple: multiple,
                disabled: $scope.ngDisabled,
                bindType: attrs.csBindType,
                code: code,
                parameters: parameters,
                param: $scope.csOption,
                getKey: function (select) {
                    return select.Key;
                },
                getText: function (select) {
                    return select.Value;
                },

                getObj: function (key, value) {
                    return { Key: key, Value: value };
                }
            };

            $scope.selectChange = function () {
                if (attrs.ngChange) {
                    $parse(attrs.ngChange)($scope.$parent);
                }
            };
        },
        template: '<my-base-picker option="option" ng-model="ngModel" ng-change="selectChange()" cs-bind-value="csBindValue" />'
    };
}]);